# Contributor: rubicon <rubicon@mailo.com>
# Maintainer:
pkgname=ocaml-tcpip
_pkgname=tcpip
pkgver=7.1.0
pkgrel=0
pkgdesc="OCaml TCP/IP networking stack, used in MirageOS"
url="https://github.com/mirage/mirage-tcpip"
arch="all !riscv64"  # limited by ocaml aport
license="ISC"
# ocaml-bisect_ppx only needed for dev
depends="
	ocaml-runtime
	ocaml-arp
	ocaml-cstruct
	ocaml-duration
	ocaml-ethernet
	ocaml-fmt
	ocaml-ipaddr
	ocaml-logs
	ocaml-lru
	ocaml-lwt
	ocaml-lwt-dllist
	ocaml-metrics
	ocaml-mirage-clock
	ocaml-mirage-flow
	ocaml-mirage-net
	ocaml-mirage-profile
	ocaml-mirage-random
	ocaml-mirage-time
	ocaml-randomconv
	"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-arp-dev
	ocaml-bisect_ppx-dev
	ocaml-cstruct-dev
	ocaml-duration-dev
	ocaml-ethernet-dev
	ocaml-fmt-dev
	ocaml-ipaddr-dev
	ocaml-logs-dev
	ocaml-lru-dev
	ocaml-lwt-dev
	ocaml-lwt-dllist-dev
	ocaml-metrics-dev
	ocaml-mirage-clock-dev
	ocaml-mirage-flow-dev
	ocaml-mirage-net-dev
	ocaml-mirage-profile-dev
	ocaml-mirage-random-dev
	ocaml-mirage-time-dev
	ocaml-randomconv-dev
	"
makedepends="$depends_dev dune ocaml"
checkdepends="ocaml-alcotest-dev ocaml-ipaddr-cstruct-dev ocaml-mirage-clock-unix-dev ocaml-mirage-random-test-dev ocaml-mirage-vnetif-dev ocaml-pcap-format-dev"
options="!check"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://github.com/mirage/mirage-tcpip/releases/download/v$pkgver/tcpip-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; for path in $(find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done
}

sha512sums="
fae605ba30b0bb5ae28cbedc32f220c5a5166db4af9e060d82007cd020132f1e334fa8fcb7e9bd68851fc838f7e6fb1b4e1d3cba8fb787dcec79d2107b8ffd4a  ocaml-tcpip-7.1.0.tar.bz2
"
